package com.gmail.dmitryustimov.ms.java7.visitor.mod_actionmap.example.example2;


public class CarElementDoVisitor<T> extends CarElementVisitor<T> {

    public <S extends T> CarElementDoVisitor() {
        addVisitAction((Class<S>)Wheel.class,  (VisitAction<S>)this.new DoWheel());
        addVisitAction((Class<S>)Engine.class, (VisitAction<S>)this.new DoEngine());
        addVisitAction((Class<S>)Body.class,   (VisitAction<S>)this.new DoBody());
        addVisitAction((Class<S>)Car.class,    (VisitAction<S>)this.new DoCar());
    }

    public class DoWheel implements VisitAction<Wheel> {
        @Override
        public void visit(Wheel wheel) {
            System.out.println("Kicking my " + wheel.getName() + " wheel");
        }
    }

    public class DoEngine implements VisitAction<Engine> {
        @Override
        public void visit(Engine engine) {
            System.out.println("Starting my engine");
        }
    }

    public class DoBody implements VisitAction<Body> {
        @Override
        public void visit(Body body) {
            System.out.println("Moving my body");
        }
    }

    public class DoCar implements VisitAction<Car> {
        @Override
        public void visit(Car car) {
            visitCar(car, CarElementDoVisitor.this);
            System.out.println("Starting my car");
        }
    }
}
